<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">日志管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">日志管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">
		<div class="row mbl" >
			<div class="col-lg-12">
				<form action="./logdownload.do" method="post" name="aa" id="down_form" target="_blank">
					<input type="hidden" class="form-control" id="downType" name="downType" />
					<table style="width: 95%;">
						<tr height="50">
							<td align="right" style="width: 100px;">日志类型&nbsp;&nbsp;</td>
							<td>
								<select class="form-control" id="logType" name="logType">
									<option value="">请选择</option>
									<option value="general_data">general_data</option>
									<option value="login">login</option>
								</select>
							</td> 
							<td align="right" style="width: 100px;">日志内容&nbsp;&nbsp;</td>
							<td><input type="text" class="form-control" style="width: 100%;" id="logText" name="logText" /></td>
							<td align="right" style="width: 100px;">ip地址&nbsp;&nbsp;</td>
							<td><input type="text" class="form-control" style="width: 100%;" id="ipAddRess" name="ipAddRess" /></td>
						</tr>
						<tr height="50">
							<td align="right" style="width: 100px;">用户名&nbsp;&nbsp;</td>
							<td>
								<select class="form-control" id="userId" name="userId">
									<option value="">请选择</option>
									<?for(user in userList){?>
										<option value="${user.id}">${user.nickname}</option>
									<?}?>
								</select>
							</td>
							<td align="right" style="width: 100px;">开始时间&nbsp;&nbsp;</td>
							<td><input type="text" class="form-control" style="width: 100%;" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="startTime" name="startTime" /></td>
							<td align="right" style="width: 100px;">结束时间&nbsp;&nbsp;</td>
							<td><input type="text" class="form-control" style="width: 100%;" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="endTime" name="endTime" /></td>
						</tr>
					</table>
				</form>
				<div style="margin-left: 100px;float: left;">
					<button type="button"  data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="demo1('1')">查询</button>
					<button type="button"  data-toggle="dropdown" class="btn btn-primary dropdown-toggle" onclick="deleteSearch()">清空筛选项</button>	
					<button type="button" class="btn btn-success dropdown-toggle" onclick="download()">数据导出</button><!--btn btn-sm btn-info btn-outlined  -->
				</div>
			</div>
		</div>
		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th >序号</th>
					<th >日志类型</th>
					<th >日志内容</th>
					<th >创建日期</th>
					<th >创建用户</th>
					<th >创建IP地址</th>
					<!-- 
					<th >可操作</th>
					 -->
				</tr>
			</thead>
			<tbody id="findLog">
			</tbody>
		</table>
			<div id="page2" style="text-align: center; margin-top: 20px;"></div>
			<div id="dataNull" class="panel-body"style="height: 90px; line-height: 50px;" align="center"></div>
		
	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var curr;
	var id;
	$(function() {
		demo1(1);
	});
	function get() {
		demo1(curr);
	}
	
	//导出
	function download(){
		layer.msg('请选择导出格式', {
			  btn: ['xml', 'Excel'],
			  yes: function(index){
			    layer.close(index);
			    $("#downType").val("xml");
			    var down_form = document.getElementById('down_form');
				down_form.submit();
			  },
			  cancel : function(index) {
			  	$("#downType").val("excel");
			  	var down_form = document.getElementById('down_form');
				down_form.submit();
			  }
			});
	}
	/* if (confirm("是否确认导出！！")) {	
		var _downiframe = $("iframe#_downiframe");
		if (_downiframe.length == 0) {
			_downiframe =$("<iframe id='_downiframe' name='_downiframe' style='display:none'></iframe>").appendTo($("body"));
		}
		_downiframe.attr("src", "logdownload.do"); 
		
	}*/
	function demo1(curr) {
		if ($.trim($("#startTime").val()).length > 1 && $.trim($("#endTime").val()).length < 1) {
			layer.msg('请选择结束时间！');
			return null;
		}
		if ($.trim($("#endTime").val()).length > 1 && $.trim($("#startTime").val()).length < 1) {
			layer.msg('请选择开始时间！');
			return null;
		}
		$.getJSON("./findAllLog.do",
			{
				"page" : curr || 1,
				"logType":$("#logType").val(),
				"logText":$("#logText").val(),
				"ipAddRess":$("#ipAddRess").val(),
				"userId":$("#userId").val(),
				"startTime":$("#startTime").val(),
				"endTime":$("#endTime").val(),
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				var str = "";
				$("#findLog").html("");
				if(res.listsize>0){
					$("#dataNull").html("");
				}else{
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				for ( var i = 0; i < res.listsize; i++) {
					str += "<tr><td>"
							+ (i + 1)
							+ "</td><td> <label id=>"
							+ res.result[i].logType
							+ "</label></td><td><label >"
							+ res.result[i].logText
							+ "</label></td><td><label >"
							+ res.result[i].createTime
							+ "</label></td><td><label >"
							+ res.result[i].createUserName
							+ "</label></td><td><label >"
							+ res.result[i].createIpAddress
							+ "</label></td>"
							//+ "<td><button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"del('"
							//+ res.result[i].id
							//+ "')\">"
							//+ "删除"
							//+ "</button>&nbsp;"
							//+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"addUpdateUser('"
							//+ res.result[i].id
							//+ "')\">"
							//+ "编辑"
							//+ "</button></td>" 
							+ "</tr>";
				}
				$("#findLog").append(str);
				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res.pageSize, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: curr || 1,
					last: res.pageSize,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo1(obj.curr);
							 var curr = obj.curr;
			                 curr=obj.curr;
						}
					}
				});
			});
	};

	function deleteSearch(){
		$("#logType").val("");
		$("#logText").val("");
		$("#ipAddRess").val("");
		$("#userId").val("");
		$("#startTime").val("");
		$("#endTime").val("");
	}
	
</script>